<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
       input{
           background-color: green;
       }
       .red{
           background-color: red;
       }
    </style>
</head>
<body>
    <input type="text" id="green1" onfocus="f(this.id)" onblur="f1(this.id)">
    <input type="text" id="green2" onfocus="f(this.id)" onblur="f1(this.id)">
    <input type="text" id="green3" onfocus="f(this.id)" onblur="f1(this.id)">
</body>
</html>
<script>
    function f(val) {
        document.getElementById(val).style.backgroundColor = "red";
    }
    function f1(val) {
        document.getElementById(val).style.backgroundColor = "green";
    }
</script>